# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer:
pkgname=tinyxml
pkgver=2.6.2
_realver=${pkgver//./_}
pkgrel=4
pkgdesc="A simple, small, C++ XML parser"
url="https://sourceforge.net/projects/tinyxml/"
arch="all"
license="Zlib"
subpackages="$pkgname-dev"
source="https://downloads.sourceforge.net/tinyxml/tinyxml_$_realver.tar.gz
	tinyxml-2.6.2-defineSTL.patch
	tinyxml-2.6.1-entity.patch
	CVE-2021-42260.patch
	CVE-2023-34194.patch
	"
builddir=$srcdir/$pkgname

# secfixes:
#   2.6.2-r4:
#     - CVE-2023-34194
#   2.6.2-r2:
#     - CVE-2021-42260

prepare() {
	default_prepare
	sed -i Makefile \
		-e '/^TINYXML_USE_STL/ s|=.*|=YES|' \
		-e "s|^RELEASE_CFLAGS.*|& $CXXFLAGS -fPIC|"
}

build() {
	make
	# shellcheck disable=2010,2035,2046
	g++ -fPIC $CXXFLAGS $LDFLAGS -shared -o libtinyxml.so.0.$pkgver \
		-Wl,-soname,libtinyxml.so.0 $(ls *.o | grep -v xmltest)
}

package() {
	install -d -m 0755 "$pkgdir"/usr/lib \
		"$pkgdir"/usr/include
	install -m 0755 libtinyxml.so.0.2.6.2 \
		"$pkgdir"/usr/lib/
	install -m 0644 tinyxml.h tinystr.h \
		"$pkgdir"/usr/include/
	cd "$pkgdir"/usr/lib
	ln -s libtinyxml.so.0.2.6.2 libtinyxml.so
	ln -s libtinyxml.so.0.2.6.2 libtinyxml.so.0
}

sha512sums="
133b5db06131a90ad0c2b39b0063f1c8e65e67288a7e5d67e1f7d9ba32af10dc5dfa0462f9723985ee27debe8f09a10a25d4b5a5aaff2ede979b1cebe8e59d56  tinyxml_2_6_2.tar.gz
52cd82ef9e8f1783b3d6042551342a8c592c447e1da352d5d017db4211144bc0a908ddbfe2a4641b3108fb8e02dc47f385a851f920532d94178314255904a6ef  tinyxml-2.6.2-defineSTL.patch
47d582456c2e2ac51a186a4bd58ede4895586ed373b654b120b34bedc7c2e52ed291a3576a37420ea94a238a265d8e2d38de024e770144e465590718da245af3  tinyxml-2.6.1-entity.patch
3b56148d7be8f5b1a2db00ccef2f16ebafc287edec7a766f3f8591b4ed3e213dfccd7755d2973a0a9a4e82283aaf47a55884f67cc376349639b570041de76203  CVE-2021-42260.patch
9d052467df67fa62063a31faf83a35080b92e48d5258112c1fd5d0609b89ad579fe08089b1c2c9986ce8a8d2d4d450872af0a76775507adc0dbc73b5101484fc  CVE-2023-34194.patch
"
